import actionRequest from '@/utils/request.ts'

type CountStruct = {
  total: number
  month_week_growth: {
    month: number
    week: number
  }
}
export const getHeadSourceTable = (): Promise<{
  data_table: CountStruct
  data_source: CountStruct
}> => {
  return actionRequest({
    url: '/v1/homepage/head/data-source-table',
    method: 'get'
  })
}
export const getHeadPlan = (): Promise<{
  count: CountStruct
  finished_rate: CountStruct
}> => {
  return actionRequest({
    url: '/v1/homepage/head/plan-order',
    method: 'get'
  })
}
export const getHeadDemand = (): Promise<{
  count: CountStruct
  delivery_data_count: CountStruct
}> => {
  return actionRequest({
    url: '/v1/homepage/head/demand-order',
    method: 'get'
  })
}
export const getHeadProject = (): Promise<CountStruct> => {
  return actionRequest({
    url: '/v1/homepage/head/project',
    method: 'get'
  })
}
export const getCardTable = (): Promise<
  CountStruct & {
    status_agg: Array<{
      status: 0 | 1 | -1
      count: number
    }>
  }
> => {
  return actionRequest({
    url: '/v1/data-assets/homepage/data-table',
    method: 'get'
  })
}
export const getCardSource = (): Promise<
  CountStruct & {
    status_agg: Array<{
      status: -1 | 1 | 2 | 3
      count: number
    }>
  }
> => {
  return actionRequest({
    url: '/v1/data-assets/homepage/data-source',
    method: 'get'
  })
}
interface TagCount {
  total: number
  month: number
  week: number
}
export const getCardTag = (): Promise<{
  tag_tree: TagCount
  tag: TagCount
  online_rule: TagCount
}> => {
  return actionRequest({
    url: '/v1/data-assets/homepage/tag-rule',
    method: 'get'
  })
}
export const getCardDemand = (): Promise<{
  count: CountStruct
  answer_rate: CountStruct
  finish_rate: CountStruct
  positive_review_rate: CountStruct
}> => {
  return actionRequest({
    url: '/v1/data-operation/homepage/demand-order/overview',
    method: 'get'
  })
}
interface OrderStruct {
  building_total: number
  month_received: number
  week_received: number
  month_finished: number
  week_finished: number
}

export const getCardPlan = (): Promise<OrderStruct> => {
  return actionRequest({
    url: '/v1/data-product/homepage/plan-order',
    method: 'get'
  })
}
export const getCardProduction = (): Promise<OrderStruct> => {
  return actionRequest({
    url: '/v1/data-product/homepage/production-order',
    method: 'get'
  })
}

// 格式 2023-04
interface TrendParams {
  month_min: string
  month_max: string
}

interface TrendStruct {
  received: Array<{
    month: string
    count: number
  }>
  finished: Array<{
    month: string
    count: number
  }>
}
export const getCardPlanTrend = (params: TrendParams): Promise<TrendStruct> => {
  return actionRequest({
    url: '/v1/data-product/homepage/order-finishing-trend/plan-order',
    method: 'get',
    params
  })
}
export const getCardProductionTrend = (params: TrendParams): Promise<TrendStruct> => {
  return actionRequest({
    url: '/v1/data-product/homepage/order-finishing-trend/production-order',
    method: 'get',
    params
  })
}
export const getCardTopRank = (): Promise<
  Array<{
    cn_table_name: string
    delivered_count: number
  }>
> => {
  return actionRequest({
    url: '/v1/data-operation/homepage/data-table-ranking',
    method: 'get'
  })
}
export const getBottomAssets = (): Promise<CountStruct> => {
  return actionRequest({
    url: '/v1/homepage/bottom/data-assets',
    method: 'get'
  })
}

interface BottomStruct {
  using_total: number
  month_received: number
  week_received: number
  month_finished: number
  week_finished: number
}
export const getBottomDemand = (): Promise<BottomStruct> => {
  return actionRequest({
    url: '/v1/homepage/bottom/demand-order',
    method: 'get'
  })
}
export const getBottomPlan = (): Promise<BottomStruct> => {
  return actionRequest({
    url: '/v1/homepage/bottom/plan-order',
    method: 'get'
  })
}
export const getBottomProduction = (): Promise<BottomStruct> => {
  return actionRequest({
    url: '/v1/homepage/bottom/production-order',
    method: 'get'
  })
}
